package com.sdl.timesblogmp.controller;


import com.sdl.timesblogmp.model.entity.Uploadfile;
import com.sdl.timesblogmp.model.vo.ApiResult;
import com.sdl.timesblogmp.model.vo.PageParam;
import com.sdl.timesblogmp.service.UploadfileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sdl
 * @since 2020-05-11
 */
@Api(value = "上传文件接口", tags = "上传文件接口")
@RestController
@RequestMapping("/file")
public class FileController {
    @Resource
    private UploadfileService uploadfileService;
    @ApiOperation(value = "获取所有文件")
    @GetMapping("/list")
    public ApiResult getalluploadfile( PageParam pageParam){
        return ApiResult.success(uploadfileService.findUploadfileInfo(pageParam)) ;
    }
    @ApiOperation(value = "上传一个文件")
    @PostMapping("/upload")
    public ApiResult upload(MultipartFile file){
        return ApiResult.success(uploadfileService.uploadfile(file));
    }
    @ApiOperation(value = "删除一个文件")
    @DeleteMapping("/del/{id}")
    public ApiResult delfile(@PathVariable Integer id) {
        uploadfileService.deletefile(id);
        return ApiResult.success();
    }
    @ApiOperation(value = "获取一个文件")
    @GetMapping("{id}")
    public ApiResult getfileuel(@PathVariable Integer id) {
        return ApiResult.success(uploadfileService.getById(id));
    }
    @ApiOperation(value = "更新文件信息")
    @PutMapping("/update")
    public ApiResult update(@RequestBody Uploadfile uploadfile) {
        uploadfileService.updateById(uploadfile);
        return ApiResult.success();
    }

}

